/**
 * ReportGear(2011)
 */
package com.reportgear.report.model.headerfooter;

import com.reportgear.report.model.headerfooter.editor.ElementEditor;

/**
 * 页眉页脚元素工厂
 * 
 * @version 1.0 2011-4-23
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class HFElementFactory {
	/**
	 * 根据类型创建页眉页脚元素
	 * 
	 * @param type
	 *            元素类型
	 * @return 元素类型
	 */
	public static HFElement createElement(String type) {
		if (HFElement.TYPE_TEXT.equals(type)) {
			return new TextHFElement();
		} else if (HFElement.TYPE_PAGE_NUM.equals(type)) {
			return new PageNumHFElement();
		} else if (HFElement.TYPE_TOTAL_PAGES.equals(type)) {
			return new TotalPagesHFElement();
		} else if (HFElement.TYPE_NEWLINE.equals(type)) {
			return new NewLineHFElement();
		}

		return null;
	}

	/**
	 * 创建元素编辑器
	 * 
	 * @param type
	 *            元素类型
	 * @return 元素编辑器
	 */
	public static ElementEditor createElementEditor(String type) {
		Class<?> clazz = null;
		try {
			if (HFElement.TYPE_TEXT.equals(type)) {
				clazz = Class.forName("com.reportgear.designer.pane.headerfooter.editor.TextElementEditor");
			} else if (HFElement.TYPE_PAGE_NUM.equals(type)) {
				clazz = Class.forName("com.reportgear.designer.pane.headerfooter.editor.PageNumElementEditor");
			} else if (HFElement.TYPE_TOTAL_PAGES.equals(type)) {
				clazz = Class.forName("com.reportgear.designer.pane.headerfooter.editor.TotalPagesElementEditor");
			} else if (HFElement.TYPE_GROUP_PAGE_NUM.equals(type)) {
				clazz = Class.forName("com.reportgear.designer.pane.headerfooter.editor.GroupPageNumElementEditor");
			} else if (HFElement.TYPE_GROUP_TOTAL_PAGES.equals(type)) {
				clazz = Class.forName("com.reportgear.designer.pane.headerfooter.editor.GroupTotalPagesElementEditor");
			} else if (HFElement.TYPE_NEWLINE.equals(type)) {
			}

			if (clazz != null) {
				return (ElementEditor) clazz.newInstance();
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}

		return null;
	}

}
